﻿#ifndef VIDEOWINDOW_H
#define VIDEOWINDOW_H

#include <QMainWindow>
#include <QSettings>
#include <QGraphicsScene>
#include <QGraphicsVideoItem>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QMultimedia>

namespace Ui {
class VideoWindow;
}

class VideoWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit VideoWindow(QSettings* settings, QWidget *parent = nullptr);
    ~VideoWindow() override;

    // 重置视频
    void pause(bool reset = false);

protected:
    void closeEvent(QCloseEvent *event) override;
    void showEvent(QShowEvent* event) override;
    void resizeEvent(QResizeEvent *event) override;
    void timerEvent( QTimerEvent *event ) override;

private:
    void initUI();
    void init();

private:
    Ui::VideoWindow *ui;

    // 定时器ID
    int m_nTimerId;

    // GraphicsView
    QGraphicsScene* m_scene;
    QGraphicsVideoItem* m_videoItem;

    // 视频播放(播放列表)
    QMediaPlayer* m_player;
    QMediaPlaylist* m_playlist;

private:
    // INI配置文件
    QSettings* m_settings;

    // 播放计时
    bool m_playing;
    int m_timeMsecond;
    int m_playDuration;

signals:

private slots:
    void onVideoPositionChanged(qint64 position);
    void onVideoDurationChanged(qint64 duration);

public slots:
    // 根据位置和时长播放
    void onPlayByPosition(const int startTime, const int duration);
};

#endif // VIDEOWINDOW_H
